<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>hashRouter 的原理介绍</title>
    <style>
        #result{
            width: 400px;
            height: 300px;
            border:solid 1px #999;
        }
    </style>
</head>
<body>
    <a href="#home">Home</a>
    <a href="#about">About</a>

    <div id="result">

    </div>

    <script>
        let result = document.querySelector('#result');
        // console.log(window.location);
        //hashchange 的事件   页面 URL 的 hash 值发生改变之后, 触发该事件
        window.addEventListener('hashchange', function(){
            // location 对象
            let hash = window.location.hash;
            //判断
            switch(hash){
                case '#home':
                    result.innerHTML = '首页 Home Home Home';
                    break;
                case '#about':
                    result.innerHTML = '关于我们 about about about';
                    break;
            }
        });
    </script>
</body>
</html>